import { ESGeoPolygon, ESGltfModel, FeatureColorJsonType, FeatureVisableJsonType, UeESGltfModel, UeViewer } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';
import { ESFeTreeAdding } from '.';
import { UeESSceneObject } from 'xbsj-xe2/dist-node/xe2-ue-objects';
import { bind, createNextAnimateFrameEvent, track } from "xbsj-xe2/dist-node/xe2-base-utils";

// export class UeESFeTreeAdding extends UeESGltfModel<ESFeTreeAdding> {
//     static readonly type = this.register(ESFeTreeAdding.type, this);
//     constructor(sceneObject: ESFeTreeAdding, ueViewer: UeViewer) {
//         super(sceneObject, ueViewer);

//         const viewer = ueViewer.viewer;
//         if (!viewer) {
//             console.warn(`viewer is undefined!`);
//             return;
//         }
//     }
// }

export class UeESFeTreeAdding<T extends ESFeTreeAdding = ESFeTreeAdding> extends UeESSceneObject<T> {
    static readonly type = this.register<ESFeTreeAdding>(ESFeTreeAdding.type, this);
    static override combinationClass = true;

    private _eSGltfModel = this.dv(new ESGltfModel());
    get eSGltfModel() { return this._eSGltfModel; }

    constructor(sceneObject: T, ueViewer: UeViewer) {
        super(sceneObject, ueViewer);

        const viewer = ueViewer.viewer;
        if (!viewer) {
            console.warn(`viewer is undefined!`);
            return;
        }

        //属性同步
        {
            const eSGltfModel = this.eSGltfModel;
            ueViewer.add(eSGltfModel);
            this.dispose(() => ueViewer.delete(eSGltfModel))

            this.d(track([eSGltfModel, 'url'], [sceneObject, 'url']));
            this.d(bind([eSGltfModel, 'editing'], [sceneObject, 'editing']));

            this.d(bind([eSGltfModel, 'position'], [sceneObject, 'position']));
            this.d(bind([eSGltfModel, 'rotation'], [sceneObject, 'rotation']));

        }

        //显隐控制
        {
            const updateShow = () => {
                this.eSGltfModel.show = sceneObject.show;
            }
            updateShow();
            this.d(sceneObject.showChanged.don(() => { updateShow() }));
        }
    }
}
